import React, { Component } from "react";
import { render } from "react-dom";
import { HashRouter, Route } from "react-router-dom";

import QMRouter from "qm-router";
import Decorator from "QMDecorator";

import entries from "./entry";
const { ChunkContainer, BundleContainer } = QMRouter;
declare let Redirect: any;

export default class App extends Component<any, any> {
  constructor(props) {
    super(props);
    this.state = {
      bundles:
        typeof $QM_ADMIN_BUNDLES !== "undefined"
          ? JSON.parse($QM_ADMIN_BUNDLES)
          : []
    };
  }

  render() {
    let { bundles } = this.state;
    return (
      <HashRouter hashType="slash">
        <Decorator>
          <div style={{ height: "100%" }}>
            <Route exact path="/" render={() => <Redirect to="/main/" />} />
            <ChunkContainer entries={entries} />
            <BundleContainer bundles={bundles} />
          </div>
        </Decorator>
      </HashRouter>
    );
  }
}

render(<App />, document.getElementById("react-content"));
